set nocompatible
filetype off "Required by vundle

let mapleader = ","
let g:mapleader = ","
set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()
Plugin 'scrooloose/syntastic'
Plugin 'airblade/vim-gitgutter'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'ilyachur/cmake4vim'
Plugin 'junegunn/fzf',
Plugin 'junegunn/fzf.vim',
Plugin 'ludovicchabant/vim-gutentags'
Plugin 'joshdick/onedark.vim'
call vundle#end()


filetype plugin indent on
set hlsearch
set ignorecase
set smartcase
set enc=utf-8
set fileencoding=utf-8
set laststatus=2
set t_Co=256
set colorcolumn=95
set number
set relativenumber
set expandtab
set smartindent
set softtabstop=2
set shiftwidth=2
set mouse=a
set backspace=indent,eol,start
set cursorline 
set guifont=Monaco:h10


"==================="
"程序开发相关的设置"
"==================="
"(1)使用%来选择语句块，然后使用快捷键zf来折叠"
set foldmethod=marker
"(2)注释：选中文本后，输入;c即可注释，输入;u 即可取消注释"
vmap <silent> ;c :s/^/\/\//<CR>:noh<CR>
vmap <silent> ;u :s/\/\///<CR>:noh<CR>

"============"
"多窗口操作"
"============"
map <C-l> <C-W>l
map <C-h> <C-W>h
map <C-j> <C-W>j
map <C-k> <C-W>k

"=========================="
"不要交换文件和备份文件，减少冲突"
"=========================="
set noswapfile
set nobackup
set nowritebackup

"============="
"查找和替换文本"
"============="
nmap ;s :%s/\<<C-R>=expand("<cword>")<CR>\>/
nmap ;g :vimgrep <C-R>=expand("<cword>")<CR> */*.*

"========================"
"快捷文本输入"
"========================"
map <silent>  \d a<C-R>=strftime("%Y/%m/%d %A")<CR> 
map <silent>  \t a<C-R>=strftime("%Y/%m/%d %H:%M:%S")<CR>
map <silent>   ,d :split ~/Dropbox/Doc/ <CR>
iab --l  --------------------
iab ==l  ====================


nnoremap <silent> <leader>/ :nohlsearch<CR>
inoremap jj <Esc>

map <C-c> :NERDTreeToggle<CR>

map <F7> :tabp<CR>
map <F8> :tabn<CR>
map <C-t> :vert term<CR>

autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

function! NERDTreeHighlightFile(extension, fg, bg, guifg, guibg)
  exec 'autocmd filetype nerdtree highlight ' . a:extension .' ctermbg=' . a:bg .' ctermfg=' . a:fg . ' guibg=' . a:guibg .' guifg=' . a:guifg
  exec 'autocmd filetype nerdtree syn match ' . a:extension .' #^\s\+.*'. a:extension . '$#'
endfunction

"设置ctags路径
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
"启动vim后自动打开taglist窗口
let Tlist_Auto_Open = 1
"不同时显示多个文件的tag，仅显示一个
let Tlist_Show_One_File = 1
"taglist为最后一个窗口时，退出vim
let Tlist_Exit_OnlyWindow = 1
"taglist窗口显示在右侧，缺省为左侧
let Tlist_Use_Right_Window =1
"设置taglist窗口大小
"let Tlist_WinHeight = 100
let Tlist_WinWidth = 40
"设置taglist打开关闭的快捷键F8
noremap <F8> :TlistToggle<CR>
"更新ctags标签文件快捷键设置
map <F6> :!ctags -R --c++-kinds=+pl --fields=+iaS --extra=+q .<CR>

" OmniCppComplete
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_DisplayMode=1 " Class scope completion mode: always show all members
let OmniCpp_ShowScopeInAbbr=1 " show scope in abbreviation and remove the last column
" automatically open and close the popup menu / preview window
" au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
" set completeopt=menuone,menu,longest,preview

" gutentags setting
" gutentags 搜索工程目录的标志，碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']
" 所生成的数据文件的名称
let g:gutentags_ctags_tagfile = '.tags'
" 将自动生成的 tags 文件全部放入 ~/.cache/tags 目录中，避免污染工程目录
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
" 配置 ctags 的参数
" ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f opencv /usr/local/include/opencv4/
set tags+=~/.vim/tags/cpp
set tags+=~/.vim/tags/opencv
set tags+=~/.vim/tags/ceres
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
" 检测 ~/.cache/tags 不存在就新建
if !isdirectory(s:vim_tags)
   silent! call mkdir(s:vim_tags, 'p')
endif


"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
if (empty($TMUX))
  if (has("nvim"))
    "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
    let $NVIM_TUI_ENABLE_TRUE_COLOR=1
  endif
  "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
  "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
  " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
  if (has("termguicolors"))
    set termguicolors
  endif
endif
if (has("autocmd"))
  augroup colorextend
    autocmd!
    " Make `Function`s bold in GUI mode
    autocmd ColorScheme * call onedark#extend_highlight("Function", { "gui": "bold" })
    " Override the `Statement` foreground color in 256-color mode
    autocmd ColorScheme * call onedark#extend_highlight("Statement", { "fg": { "cterm": 128 } })
    " Override the `Identifier` background color in GUI mode
    autocmd ColorScheme * call onedark#extend_highlight("Identifier", { "bg": { "gui": "#333333" } })
  augroup END
endif
syntax on
let g:airline_theme='onedark'
colorscheme onedark

" set terminal internal



